const test_finally = () => {
    const code = `

     var Gua = class() {
        var new = function(name){
            this.name = name
        }
    }
    var y = 1 + add(1, 2) 
    
    `
    const tokenList = [
        {tokenValue: "var", tokenType: TokenType.keyword},
        {tokenValue: 'Gua', tokenType: TokenType.variable},
        {tokenValue: '=', tokenType: TokenType.assign},
        {tokenValue: 'class', tokenType: TokenType.keyword},
        {tokenValue: '(', tokenType: TokenType.parenthesesLeft},
        {tokenValue: ')', tokenType: TokenType.parenthesesRight},
        {tokenValue: '{', tokenType: TokenType.curlyLeft},

        // {tokenValue: "var", tokenType: TokenType.keyword},
        // {tokenValue: 'new', tokenType: TokenType.variable},
        // {tokenValue: '=', tokenType: TokenType.assign},
        // {tokenValue: 'function', tokenType: TokenType.keyword},
        // {tokenValue: '(', tokenType: TokenType.parenthesesLeft},
        // {tokenValue: 'name', tokenType: TokenType.variable},
        // {tokenValue: ',', tokenType: TokenType.comma},
        // {tokenValue: ')', tokenType: TokenType.parenthesesRight},
        // {tokenValue: '{', tokenType: TokenType.curlyLeft},
        //
        // {tokenValue: "this", tokenType: TokenType.variable},
        // {tokenValue: '.', tokenType: TokenType.dot},
        // {tokenValue: 'name', tokenType: TokenType.variable},
        // {tokenValue: '=', tokenType: TokenType.assign},
        // {tokenValue: "name", tokenType: TokenType.variable},
        // {tokenValue: ";", tokenType: TokenType.semicolon},
        // {tokenValue: '}', tokenType: TokenType.curlyRight},

        {tokenValue: '}', tokenType: TokenType.curlyRight},
        // {tokenValue: "var", tokenType: TokenType.keyword},
        // {tokenValue: 'y', tokenType: TokenType.variable},
        // {tokenValue: '=', tokenType: TokenType.assign},
        // {tokenValue: 1, tokenType: TokenType.number},
        // {tokenValue: '+', tokenType: TokenType.plus},
        // {tokenValue: 'add', tokenType: TokenType.variable},
        // {tokenValue: '(', tokenType: TokenType.parenthesesLeft},
        // {tokenValue: 1, tokenType: TokenType.number},
        // {tokenValue: ',', tokenType: TokenType.comma},
        // {tokenValue: 2, tokenType: TokenType.number},
        // {tokenValue: ',', tokenType: TokenType.comma},
        // {tokenValue: ')', tokenType: TokenType.parenthesesRight},

        {tokenValue: ";", tokenType: TokenType.semicolon},
    ]
    const result = parser(tokenList, 0)
    log("res", result)
}


// this.a = 1
const test_dot_1 = () => {
    const code = `
        this.a = 1
    `

    const tokenList = [
        {tokenValue: "this", tokenType: TokenType.variable},
        {tokenValue: '.', tokenType: TokenType.dot},
        {tokenValue: 'a', tokenType: TokenType.variable},
        {tokenValue: '=', tokenType: TokenType.assign},
        {tokenValue: 1, tokenType: TokenType.number},
        {tokenValue: ";", tokenType: TokenType.semicolon},


    ]

    const expect = [{
        type: AstType.ExpressionAssignment,
        operator: {
            tokenType: TokenType.assign,
            tokenValue: '=',
        },
        left: {
            type: AstType.ExpressionMember,
            object: {
                type: TokenType.variable,
                value: 'this',
            },
            property: {
                type: TokenType.variable,
                value: 'a',
            }
        },
        right: {
            type: TokenType.number,
            value: 1,
        },
    }]
    log("expect", expect)
    const result = parser(tokenList, 0)
    ensure(equals(result, expect), '### test_expression_class')
}
const test_dot_2 = () => {
        const code = `
        this.add(2)
    `
        const tokenList = [
            {tokenValue: "this", tokenType: TokenType.variable},
            {tokenValue: '.', tokenType: TokenType.dot},
            {tokenValue: 'add', tokenType: TokenType.variable},
            {tokenValue: '(', tokenType: TokenType.parenthesesLeft},
            {tokenValue: 2, tokenType: TokenType.number},
            {tokenValue: ",", tokenType: TokenType.comma},
            {tokenValue: ')', tokenType: TokenType.parenthesesRight},
            {tokenValue: ";", tokenType: TokenType.semicolon},


    ]

    const expect = [{
        type: AstType.ExpressionCall,
        callee: {
            type: AstType.ExpressionMember,
            object: {
                type: TokenType.variable,
                value: 'this',
            },
            property: {
                type: TokenType.variable,
                value: 'add',
            }

        },
        arguments: [
            {
                type: TokenType.number,
                value: 2,
            },
        ],
        }]
    log("expect", expect)
    const result = parser(tokenList, 0)
    ensure(equals(result, expect), '### test_expression_class')
}

const test = () => {
    // test

    // test_DeclarationVariable_1()
    // test_expression_object()
    // test_expression_function()
    // test_expression_function_call()
    // test_expression_assignment()
    // test_expression_array()
    // test_expression_binary()
    // test_access_array()
    // test_expression_class()
    // test_StatementIf_1()
    // test_StatementIf_2()
    // test_StatementIf_3()
    // test_StatementIf_4()
    // test_StatementWhile_1()
    // test_StatementFor_1()

    // test5()
    // test_finally()
    test_finally()
    // test_dot_2()
}



const _main = () => {
    test()
}
_main()


// 直接是variable的情况
//a[0]
//add(1, 2)
//item.log(1, 2)
//this.a

// a = 1
// this.a = 1

//if的condition问题，复杂condotion，现在只有一种情况可以适用
//for